package com.tanhua.server.controller;

import com.tanhua.domain.vo.RecommendUserQueryVO;
import com.tanhua.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;

    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        return tanhuaService.todayBest();
    }

    /**
     * 交友-推荐
     * GET /tanhua/recommendation
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendUserQueryVO queryVO) {
        return tanhuaService.recommendation(queryVO);
    }

    /**
     * 交友-查看佳人信息
     * GET /tanhua/:id/personalInfo
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id")Long userId) {
        return tanhuaService.findPersonalInfo(userId);
    }
    /**
     * 交友-查看陌生人问题
     * GET /tanhua/strangerQuestions
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity findStrangerQuestion(Long userId) {
        return tanhuaService.findStrangerQuestion(userId);
    }

    @PostMapping
            ("/strangerQuestions")
    public ResponseEntity replyStrangerQuestion(@RequestBody Map map) {
        Long targetUserId = Long.parseLong(map.get("userId").toString());
        String reply = (String) map.get("reply");
        return tanhuaService.replyStrangerQuestion(targetUserId, reply);
    }
    /**
     * 探花-搜附近
     * GET /tanhua/search
     */
    @GetMapping("/search")
    public ResponseEntity searchNear(@RequestParam(required = false) String gender,
                                     @RequestParam(defaultValue = "2000") Integer distance){
        return tanhuaService.searchNear(gender, distance);
    }

    /**
     * 探花-左滑右划
     * GET/tanhua/cards
     */
    @GetMapping("/cards")
    public ResponseEntity cards() {
        return tanhuaService.cards();
    }

    /**
     * 探花-喜欢
     * GET/tanhua/:id/love
     */
    @GetMapping("/{id}/love")
    public ResponseEntity tanhuaLove(@PathVariable("id") Long loveId) {
        return tanhuaService.tanhuaLove(loveId);
    }

    /**
     * 探花-不喜欢
     * GET/tanhua/:id/unlove
     */
    @GetMapping("/{id}/unlove")
    public ResponseEntity tanhuaUnLove(@PathVariable("id") Long unLoveId) {
        return tanhuaService.tanhuaUnLove(unLoveId);
    }

}